<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>CSC560 Design and Analysis of Real-Time Systems</title>
<meta name="keywords" content="CSC560" />
<meta name="description" content="CSC560" />
<link href="../default.css" rel="stylesheet" type="text/css" />
<!-- Needed for Code Highlighter -->
<script type="text/javascript" src="../scripts/shCore.js"></script>
<script type="text/javascript" src="../scripts/shBrushBash.js"></script>
<script type="text/javascript" src="../scripts/shBrushCpp.js"></script>
<link type="text/css" rel="stylesheet" href="../styles/shCore.css"/>
<link type="text/css" rel="stylesheet" href="../styles/shThemeDefault.css"/>
<script type="text/javascript">
	SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
	SyntaxHighlighter.all();
</script>
<!-- End of Needed for Code Highlighter -->
</head>
<body>
<div id="wrapper">
	<div id="header">
		<h1>CSC560</h1>
		<h2>Design and Analysis of Real-Time Systems</h2>
		<ul>
			<li class="first"> <a href="../index.html" accesskey="1" title="">Home</a> </li>
			<li> <a href="../project1/index.html" accesskey="2" title="">Project 1</a>	</li>
			<li> <a href="../project2/index.html" accesskey="3" title="">Project 2</a> </li>
			<li> <a href="index.html" accesskey="4" title=""><b>Project 3</b></a> </li>
			<li> <a href="../project4/index.html" accesskey="4" title="">Project 4</a> </li>
			<li> <a href="../project5/index.html" accesskey="4" title="">Project 5</a> </li>
		</ul>
	</div>
</div>
<div id="content">
	<div id="colOne">
		<h2>Logic Analyzer</h2>
		<p>
			We have used the logic analyzer to increase testing our RTOS.<br><br>
			The first test is to verify that two BRR tasks interleave correctly.
			Instead of using two probes for the test case, we have decided to use only one.
			When the the first BRR task starts running, the pin is pulled high. When the second 
			BRR task runs, it pulls the same pin low. The following code snippet shows how this was 
			implemented.
<pre class="brush: c;">
void generic_task1(void) {
	for (;;) {
		PORTD |= _BV(PORTD7);
	}
}
</pre>

<pre class="brush: c;">
void generic_task2(void) {
	for (;;) {
		PORTD &= 0x00;
	}
}
</pre>

<pre class="brush: c;">
int main(void) {
	//use pins 7 on Port D for output
	DDRD = (1&lt;&lt;PORTD7);

    Task_Create(generic_task,0, BRR, 1);
    Task_Create(generic_task2,0, BRR, 1);

    return 0;
}
</pre>
			
		</p>
		The following picture shows the first BRR running for 1 tick (5 ms approximately) when the pin is high, 
		and the second BRR also runs for 1 tick when the pin low. 
		<p>
			<a href="images/logic_analyzer1.jpg"><img src="images/logic_analyzer1.jpg" alt="Logic Analyzer test 1" width="100%" /></a>
		</p>
		<p>
		The second test case verifies a periodic task and a BRR task. Similarly to the first test case, we have used
		only one pin to create the test case. The periodic task pulls the pin high when it starts running, whereas the
		BRR tasks pulls the pin low when it starts running. The following code shows how we have implemented the test
		case. 
		</p>
		<pre class="brush: c;">
const unsigned char PPP[] = {1,2};
const unsigned int PT = sizeof(PPP)/2;

void generic_task1(void) {
    for(;;) {
		PORTD |= _BV(PORTD7);
    	Task_Next();
    }
}

void generic_task2(void) {
    for(;;) {
    	PORTD &= 0x00;
    	Task_Next();
    }
}

int main(void) {
	DDRD = (1&lt;&lt;PORTD7);

    Task_Create(generic_task1,1, PERIODIC,1);
    Task_Create(generic_task2, 0, BRR, 1);

    return 0;
}
		</pre>
		<p>
		The following screenshot displays the logic analyzer result. We can see that every 2 ticks, the periodic task
		starts running (pin is high), and in between, the BRR keeps running (pin is low).
		</p>
		
		<p>
			<a href="images/logic_analyzer2.png"><img src="images/logic_analyzer2.png" alt="Logic Analyzer test 2" width="100%"/></a>
		</p>
		
		<p>
		The third test case implemented demonstrates the interaction between a system, periodic, and BRR task. For this test case,
		we have used 3 input lines on the logic analyzer. Input 1 corresponds to the system task, input 2 corresponds to the periodic
		task, and input 3 corresponds to BRR task. On the AT90USBKey, pins PD5, PD6, and PD7 were assigned to input 1, 2, and 3 
		respectively. 
		</p>
		
		<p>
			The following snippets of code shows how our test case was implemented.
		</p>
		
		<pre class="brush: c;">
		//periodic tasks runs for 3 ticks
		const unsigned char PPP[] = {1,3};
		const unsigned int PT = sizeof(PPP)/2;
		</pre>
		
		<pre class="brush: c;">
		void system_task(void)
		{
			PORTD |= _BV(PORTD5);
			PORTD &= 0x00;
		
			Task_Next();
		}
		</pre>

		<pre class="brush: c;">
		void periodic_task(void)
		{
			for (;;) {
				PORTD |= _BV(PORTD6);
				PORTD &= 0x00;
		
				Task_Create(system_task,2,SYSTEM,2);
				Task_Next();
			}
		}
		</pre>

		<pre class="brush: c;">
		void brr_task(void)
		{
			for (;;) {
				PORTD |= _BV(PORTD7);
				PORTD &= 0x00;
				Task_Next();
			}
		}
		</pre>

		<pre class="brush: c;">
		int main(void) {
			DDRD = (1&lg;&lg;PORTD5) | (1&lg;&lg;PORTD6) | (1&lg;&lg;PORTD7);
		
		    Task_Create(periodic_task,1,PERIODIC,1);
		    Task_Create(brr_task,0, BRR, 1);
		
		    return 0;
		}
		</pre>
		
		<p>
			According to the test case, a periodic task is first scheduled and creates a system task. Once the system task is 
			created, it preempts the periodic task and runs until completion. Once finished, since the periodic task is not scheduled
			before its next period (3 ticks), the BRR task is scheduled. The BRR task has a quantum of 1 and fits in the time before
			the next periodic task begins. Therefore, it is scheduled by RTOS.
		</p>
		
		<p>
			The following pictures display the timing results of each task. We can see that the system task is only scheduled once the
			periodic task has been scheduled (since the periodic task creates the system task). We can also observe that the periodic
			task runs approximately every 15 ms (3 tick), which is equal to its period. Within the time the system task finishes and 
			before the next periodic tasks is scheduled, the BRR task has enough time to run.
		</p>
		
		<p>
			<a href="images/logic_analyzer3.jpg"><img src="images/logic_analyzer3.jpg" alt="Logic Analyzer test 3" width="100%"/></a>
		</p>
		<p>
			The picture below is the same as the first one above except that it is zoomed in. As we can see, the BRR is scheduled 
			3 times for approximately 1 tick (5 ms), before the next periodic task runs. In the figure T0 represent the time the BRR
			starts, and T1 represents the time the BRR finishes its tick. This process is repeated 2 more times.
		</p>
		
		<p>
			<a href="images/logic_analyzer4.jpg"><img src="images/logic_analyzer4.jpg" alt="Logic Analyzer test 4" width="100%"/></a>
		</p>
		
	</div>
	<div id="colTwo">
		<h3>Project Sections</h3>
		<ul>
			<li class="first"><a href="part1_brr.html">Bounded Round Robin</a></li>
			<li><a href="part2_mutex.html">Timed Mutex</a></li>
			<li><a href="part3_test_cases.html">Test Cases</a></li>
			<li><a href="part4_logic_analyzer.html"><b>Logic Analyzer</b></a></li>
			<li><a href="doxygen/html/index.html">Doxygen</a></li>
			<li><a href="http://code.google.com/p/wireless-roomba">Google Code</a></li>
		</ul>
	</div>
</div>
<div id="footer">
	<p>
		@ 2009. All Rights Reserved. Design by 
		<a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.
	</p>
</div>
</body>
</html>
